package org.scohen.juploadr.app;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.scohen.juploadr.Messages;
import org.scohen.juploadr.ui.Task;

public class RescaleTask extends Task {
    private LinkedList<UploadImage> photos;
    private List unscaled;
    private int current;
    private String currentPhotoTitle;

    public RescaleTask(List unscaled) {
        this.min = 0;
        this.max = unscaled.size();
        this.unscaled = unscaled;
        this.photos = new LinkedList<UploadImage>();
    }

    public String getTitle() {
        return Messages.getString("juploadr.ui.task.rescale.resizing.title", max); //$NON-NLS-1$ 
    }

    public void execute() {
        current = min;
        Iterator iter = unscaled.iterator();
        while (iter.hasNext()) {
            UploadImage photo = (UploadImage) iter.next();
            currentPhotoTitle = photo.getTitle();
            this.updateProgress(++current);
            photos.add(new RescaledImageAttributes(photo));
        }
    }

    public String getMessage() {
        if (currentPhotoTitle == null) {
            return Messages.getString("juploadr.ui.task.rescale.begining"); //$NON-NLS-1$
        }
        return Messages.getString("juploadr.ui.task.rescale.resizing", currentPhotoTitle, current, max); //$NON-NLS-1$
    }

    public LinkedList<UploadImage> getRescaledPhotos() {
        return photos;
    }
}
